<!--
 * @Descripttion: 主页面路由的入口
 * @version: 
 * @Author: lyw
 * @Date: 2022-02-10 15:13:15
 * @LastEditors: fengweicong 75202172+fengweicong@users.noreply.github.com
 * @LastEditTime: 2022-07-14 17:05:58
-->
<template>
  <div id="app">
    <views/>
  </div>
</template>

<script>
import views from "@/views";
export default {
  name: "app",
  components: {
    views
  },
  created() {
    //在页面加载时读取sessionStorage里的状态信息
    if (sessionStorage.getItem('store')) {
      this.$store.replaceState(JSON.parse(sessionStorage.getItem('store')));
    } else if (localStorage.getItem('Account_id')) { //页面存有就可不用登录，可设置时限
      this.$store.state.user.account_id = JSON.parse(localStorage.getItem('Account_id'));
    }
    
    //在页面刷新时将vuex里的信息保存到sessionStorage里
    window.addEventListener('beforeunload', () => {
      sessionStorage.setItem('store', JSON.stringify(this.$store.state));
    });

  },
  beforeDestroy() {
    window.removeEventListener('beforeunload',()=>{})
  }
}
</script>


